import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { Router } from '@angular/router';
import { LoginUser, RoleRight, $ } from '../../../kalend';
import { SchedulerEvent } from '@progress/kendo-angular-scheduler';
import { NzMessageService } from 'ng-zorro-antd';
import { PlatformuserService } from 'src/app/service/platformuser.service';
// import { displayDate, sampleData } from './events-utc';
@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss'],
  providers: [PlatformuserService]
})
export class HeaderComponent implements OnInit {
  isVisible = false;
  doc: any = {};
  dateTime: String;
  visible = false;
  public selectedDate: Date;
  public events: SchedulerEvent[];
  userid: any;
  baseData: any;
  user: any = RoleRight.getStorage();
  @ViewChild('pwdEdit') pwdEdit: ElementRef;
  constructor(private router: Router, private service: PlatformuserService, private msg: NzMessageService) { }

  ngOnInit() {
    this.getNetDate();
  }

  getNetDate() {
    const dateNow = new Date();
    const weeks = ['日', '一', '二', '三', '四', '五', '六'];
    this.dateTime = `${dateNow.getFullYear()}年${dateNow.getMonth() + 1}月${dateNow.getDate()}日 星期${weeks[dateNow.getDay()]}`;
  }
  exit() {
    LoginUser.loginout();
    window.localStorage.removeItem('index');
    this.router.navigate(['/login']);
  }

  close(): void {
    this.visible = false;
  }
  changePwd = () => {
    this.isVisible = true;
  }

  handleOk(): void {
    if (!this.doc.password) {
      this.msg.warning('请输入原始密码');
    } else if (!this.doc.newpass) {
      this.msg.warning('请输入新密码');
    } else if (this.doc.newpass.length < 6) {
      this.msg.warning('密码长度最少6位');
    } else if (!this.doc.newpass2) {
      this.msg.warning('请再次输入新密码');
    } else if (this.doc.newpass2 !== this.doc.newpass) {
      this.msg.warning('两次输入密码不一致');
    } else {
      this.doc.uid = this.user._id;
      this.service.editPass(this.doc).then((res) => {
        this.msg.success('修改密码成功');
        this.isVisible = false;
        this.doc = {};
      });
    }
  }
  handleCancel(): void {
    this.isVisible = false;
    this.doc = {};
  }
}
